package ch.electronet.wjw.web.actions;

import java.io.File;

import javax.servlet.ServletContext;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.util.ServletContextAware;

import ch.electronet.wjw.index.Index;
import ch.electronet.wjw.model.Preferences;
import ch.electronet.wjw.web.Picture;

import com.opensymphony.xwork2.ActionSupport;

public class PreferencesAction extends ActionSupport implements ServletContextAware {

	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unused")
	private Log log = LogFactory.getLog(PreferencesAction.class);

	private Preferences preferences;

	public Preferences getPreferences() {
		return preferences;
	}

	public void setPreferences(Preferences preferences) {
		this.preferences = preferences;
	}

	@Override
	public String execute() throws Exception {
		preferences.setPicturesRealPath(context.getRealPath(StringUtils.join(new String[] { context.getContextPath(), preferences.getPicturesPath() }, File.separator)));
		return SUCCESS;
	}

	private Index<Picture> picturesIndex;
	private ServletContext context;

	public Index<Picture> getPicturesIndex() {
		return picturesIndex;
	}

	public void setPicturesIndex(Index<Picture> picturesIndex) {
		this.picturesIndex = picturesIndex;
	}

	public void setServletContext(ServletContext context) {
		this.context = context;
	}

}
